<template>
  <!-- // 分配角色 -->
  <div>
    这里将来会放置多选列表
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>

    </el-checkbox-group>
    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hSubmit">确定</el-button>
      <el-button @click="hCancel">取消</el-button>
    </div>
  </div>
</template>
<script>
import { settingslist } from '@/api/settings'
import { getUserByID } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    curId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      // 默认选中框的id
      roleIds: [],
      // 角色列表
      list: [],
      pageForm: {
        page: 1,
        pagesize: 200
      }
    }
  },
  //   created() {
  //     this.settingslists()
  //   },
  methods: {
    hCancel() {
      this.$emit('close')
    },
    // 确定按钮
    // 保持修改
    async hSubmit() {
      try {
        await assignRoles({ id: this.curId, roleIds: this.roleIds })
        // console.log(res)
        this.$message.success('给用户分配角色成功')
        this.$emit('aSuccess')
      } catch (error) {
        console.log(error)
      }
    },
    // 默认列表
    async settingslists() {
      try {
        const res = await settingslist(this.pageForm)
        const info = await getUserByID(this.curId)
        // console.log(info, 'info')
        // console.log('getEmployeeList', res)
        this.list = res.data.data.rows
        this.roleIds = info.data.data.roleIds
        // 保存数据
      } catch (err) {
        console.log('settingslist', err)
      }
    },
    resetForm() {
      this.roleIds = []
    }
  }
}
</script>
